package com.cloudcross.ssp.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloudcross.ssp.model.Direct;
import com.cloudcross.ssp.service.IDirectService;
import com.cloudcross.ssp.base.dao.GenericIBatisDao;
import com.cloudcross.ssp.common.utils.MapBuilder;
import com.cloudcross.ssp.common.utils.Pager;

@Service
public class DirectService implements IDirectService {
	@Autowired
	private GenericIBatisDao iBatisDao;
	
	@Override
	public boolean add(Direct t) {
		t.setUpdated(new Date().getTime()/1000);
		iBatisDao.save("directSqlMapper.addDirect", t);
		return  true;
	}
	
	@Override
	public boolean edit(Direct t) {
		t.setUpdated(new Date().getTime()/1000);
		iBatisDao.save("directSqlMapper.editDirect", t);
		return true;
	}
	
	
	
	@Override
	public Direct findByadGroupId(Long adGroupId, Integer directType) {
		return 	iBatisDao.get("directSqlMapper.findByAdGroupId",MapBuilder.create(HashMap.class)
				.add("adGroupId", adGroupId)
				.add("directType", directType)
				.map());
	}
	 
	@Override
	public List<Direct>  findByBatch(Long adGroupId ) {
		
		return 	iBatisDao.getList("directSqlMapper.findByAdGroupId",MapBuilder.create(HashMap.class)
				.add("adGroupId", adGroupId)
				.map());
	}
		
	
	@Override
	public boolean deleteByadGroupId(Long adGroupId, Integer directType) {
		iBatisDao.delete("directSqlMapper.deleteDirect", MapBuilder.create(HashMap.class)
				.add("adGroupId", adGroupId)
				.add("directType", directType)
				.map());
		return true;
	}
	@Override
	public Direct findById(Long id) {
		throw new UnsupportedOperationException();
	}
	
	@Override
	public List<Direct> findByParams(Map<String, Object> paramMap, Pager pager) {
		throw new UnsupportedOperationException();
	}
	
	@Override
	public boolean updateStatus(List<Long> idList, int status) {
		throw new UnsupportedOperationException();
	}

	@Override
	public int countByParams(Map<String, Object> paramMap) {
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean copyTargetShow(long oldadgroupId,long newadgroupId){
		Map<String,Object>condition = new HashMap<String,Object>();
		condition.put("oldadgroupId", oldadgroupId);
		condition.put("newadgroupId", newadgroupId);
		Date date = new Date();
		long updated = date.getTime()/1000;
		condition.put("updated", updated);
		iBatisDao.save("directSqlMapper.copytargetshow", condition);
		return true;
	}
}
